import { useState } from "react";
import { useMutation } from "convex/react";
export const useApiMutation = (mutationFunction: any) => {
    const [pending, setPending] = useState(false);
    const apiMutation = useMutation(mutationFunction);
  
    const mutate = (payload: any) => {
      setPending(true);
      return apiMutation(payload)
        .then((result) => {
          setPending(false);
          return result;
        })
        .catch((error) => {
          setPending(false);
          throw error;
        });
    };
  
    return { mutate, pending };
  };